package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Mapper
public interface AddressBookMapper {
    //新增地址
    @Insert("insert into address_book(user_id, consignee, sex, phone, province_code, province_name, city_code, city_name, district_code, district_name, detail, label)"
    +"VALUES (#{userId},#{consignee},#{sex},#{phone},#{provinceCode},#{provinceName},#{cityCode},#{cityName},#{districtCode},#{districtName},#{detail},#{label})")
    void add(AddressBook addressBook);

    //根据userId查出所有地址
    @Select("select * from address_book where user_id=#{iuserId}")
    List<AddressBook> list(Long userId);

    //设置默认地址
    @Update("update address_book set is_default=#{isDefault} where id=#{id}")
    void setDefault(AddressBook addressBook);

    //清除所有默认地址
    @Update("update address_book set is_default=#{digit}")
    void clearAllDefault(Long digit);

    //查询默认地址
    @Select("select * from address_book where is_default=1")
    AddressBook getDefault();

    //根据id查询地址
    @Select("select * from address_book where id=#{id}")
    AddressBook getAddressById(Long id);

    //根据id修改地址
    void updateAddressById(AddressBook addressBook);

    //根据id删除地址
    @Delete("delete from address_book where id=#{id}")
    void deleteAddressById(Long id);
}
